package repositories

import (
	"context"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"signature-service/global"
)

type ChainUserConfig struct {
	ID             primitive.ObjectID `bson:"_id" json:"_id"`
	ChainName      string             `bson:"chainName" json:"chainName"`
	ChainID        int64              `bson:"chainId" json:"chainId"`
	CollectAddress string             `bson:"collectAddress" json:"collectAddress"`
	UserID         string             `bson:"userId" json:"userId"`
	ChainConfigID  string             `bson:"chainConfigId" json:"chainConfigId"`
	FeeAddress     string             `bson:"feeAddress" json:"feeAddress"`
	Rate           int                `bson:"rate" json:"rate"`
	MaxNumber      int64              `bson:"maxNumber" json:"maxNumber"`
	FeePrivateKey  string             `bson:"feePrivateKey" json:"feePrivateKey"`
}

// GetChainConfig 根据id获取链配置
func (s *ChainUserConfig) GetChainConfig(id string) error {
	client := global.DBEngine.Database(global.DBName).Collection("chain_user_config")
	objectID, err := primitive.ObjectIDFromHex(id)
	if err != nil {
		return err
	}
	filter := bson.M{"_id": objectID}
	err = client.FindOne(context.TODO(), filter).Decode(&s)
	return err
}
